﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Configuration;
using LINQtoLDAPDemo_Model;
using LinqToLdap; // TODO: I would like to get rid of these and rely on LINQtoLDAPDemo_Model for all my LDAP needs

namespace LINQtoLDAPDemo_Console
{
    class Program
    {
        static void Main(string[] args)
        {
            ListEmployeesByGroup();

            Console.Write("Press any key to continue...");
            Console.ReadKey();
        }

        private static void ListEmployeesByGroup()
        {
            Group[] groups = Group.GetAllGroups();
            int pagesize = 15;

            foreach (Group group in groups)
            {
                var members = Group.GetUserPagesByGroupMembershipStatus(group, pagesize, true);

                Console.WriteLine(group.ToString());
                if (members.ToArray()[0].Count == 0)
                {
                    Console.WriteLine("No members listed.");
                }
                else
                {
                    foreach (var u in members)
                    {
                        PrintPage<User>(u);
                    }
                }
            }
        }

        private static void PrintPage<T>(LinqToLdap.Collections.ILdapPage<T> page)
        {
            page.Select(item => item).ToList().ForEach(item => Console.WriteLine(item.ToString()));

            Console.WriteLine(); // space
        }
    }
}
